layui.use(['form', 'table', 'layer', 'layedit'], function (form, table, layer, layedit) {
    var params = getParams();
    var mailId = parseInt(params.id);
    layer.ready(function () {
        console.log(mailId);
        $.ajax({
            url: "../email/" + mailId,
            success: function (data) {
                console.log(data);
                //给表单赋值
                form.val("sendMail_form", { //formTest 即 class="layui-form" 所在元素属性 lay-filter="" 对应的值
                    "toMail": data.obj.toMail,
                    "title": data.obj.title,
                    "mailContent": data.obj.mailContent
                });
            }
        });
    });

    //返回 return
    $(document).on("click", "#return", function () {
        window.location.href = "spam.html";
    });

    // 删除
    $(document).on("click", "#del", function () {
        $.ajax({
            url: "../email/" + mailId,
            type: 'DELETE',
            success: function (data) {
                if (data.obj) {
                    layer.msg(
                        '删除成功',
                        {
                            icon: 1,
                            time: 1000
                        },
                        function () {
                            location.href = 'spam.html';
                        });
                } else {
                    layer.msg('删除失败', {icon: 2});
                }
            }
        });
    });

    //    还原
    $(document).on("click", "#reset", function () {
        $.ajax({
            url: "../email/reset/" + mailId,
            type: 'PUT',
            success: function (data) {
                if (data.obj) {
                    layer.msg(
                        '还原成功',
                        {
                            icon: 1,
                            time: 1000
                        },
                        function () {
                            location.href = 'spam.html';
                        });
                } else {
                    layer.msg('还原失败', {icon: 2});
                }
            }
        });
    });
});